<template>
  <div class="profile">
    <div class="header-con">
      <div class="user-info">
        <div class="avatar-con">
          <div class="avatar">
            <img
              v-if="!$store.state.isLogin"
              src="~assets/images/avatar_default.png"
              class="image-info"
            />
            <img
              v-else
              :src="
                require('assets/images/profile/' + $store.state.userInfo.avatar)
              "
              class="image-info"
            />
          </div>
        </div>
        <div class="person-con">
          <div v-if="!$store.state.isLogin">
            <router-link :to="{ name: 'login' }">登录</router-link>/
            <router-link :to="{ name: 'register' }">注册</router-link>
          </div>
          <div v-else>
            <div>
              <span>昵称：</span>
              {{ $store.state.userInfo.name }}
            </div>
            <div>
              <span>邮箱：</span>
              {{ $store.state.userInfo.email }}
            </div>
            <div>
              <span>手机号：</span>
              {{ $store.state.userInfo.phone }}
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="user-setting">
      <div v-for="item in cellList" :key="item.title">
        <mt-cell
          :title="item.title"
          v-if="getLoginNec(item)"
          is-link
          :to="{ name: item.linkCom }"
        >
          <span class="iconfont" :class="item.icon" slot="icon"></span>
        </mt-cell>
      </div>
    </div>

    <div class="out-box" v-if="$store.state.isLogin">
      <mt-button class="login-out" type="danger" @click="loginOut"
        >退出登录</mt-button
      >
    </div>
  </div>
</template>
<script>
export default {
  name: "Profile",
  data() {
    return {
      cellList: [
        {
          title: "我的信息",
          loginNec: true,
          linkCom: "profileInfo",
          icon: "icon-gerenxinxi",
        },
        {
          title: "物流查询",
          loginNec: true,
          linkCom: "logistics",
          icon: "icon-wuliu",
        },
        {
          title: "地址管理",
          loginNec: true,
          linkCom: "addressManage",
          icon: "icon-shouye",
        },
        {
          title: "视频专区",
          loginNec: false,
          linkCom: "profile",
          icon: "icon-shipin",
        },
        {
          title: "进购物车",
          loginNec: true,
          linkCom: "shopCart",
          icon: "icon-gouwuche",
        },
        {
          title: "关于软件",
          loginNec: false,
          linkCom: "profile",
          icon: "icon-xinxi",
        },
      ],
    };
  },
  methods: {
    loginOut() {
      this.$store.commit("loginOut");
    },
  },
  computed: {
    getLoginNec() {
      return (item) => {
        return (
          item.loginNec === false || this.$store.state.isLogin === item.loginNec
        );
      };
    },
  },
};
</script>
<style  lang="scss" scoped>
.mint-cell {
  color: #333;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.mint-cell-wrapper .iconfont {
  font-size: 20px;
  margin-right: 5px;
  vertical-align: middle;
}
.out-box {
  margin-top: 15px;
  padding: 0 20px;
}
.login-out {
  width: 100%;
}
.profile {
  margin-bottom: 15px;
  .header-con {
    padding: 10px;
    background-color: #fff;
    .user-info {
      position: relative;
      overflow: hidden;
      width: 100%;
      height: 120px;
      background: linear-gradient(90deg, #28a2ff, #ffd787);
      box-shadow: 0 0.1rem 0.25rem #f8e3c6;
      .avatar-con {
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        .avatar {
          width: 60px;
          height: 60px;
          overflow: hidden;
          box-shadow: 0 2px 10px rgba(0, 0, 0, 15);
          border: 1px solid hsla(0, 0%, 100%, 0.4);
          border-radius: 50% 50%;
          .image-info {
            width: 100%;
            height: 100%;
          }
        }
      }
      .person-con {
        position: absolute;
        left: 90px;
        top: 50%;
        transform: translateY(-50%);
        color: #fff;
      }
    }
  }
}
</style>